package net.kansun.impl;

import net.kansun.Parser;

/**
 * An implementation of {@link Parser} that parses source number in hundreds.
 * This parser will delegates relevant {@link Parser} implementations to handle low units.
 */
public class HundredsPlaceParser implements Parser {

   private Parser tensPlaceParser;
   private Parser unitParser;

   @Override
   public String parse(Long source) {

      final Long centumQuotient = source / 100;
      final Long centumReminder = source % 100;
      final StringBuilder sb = new StringBuilder("");

      if (centumQuotient > 0) {

         sb.append(unitParser.parse(centumQuotient) + " hundred");

         if (centumReminder / 10 >= 1) {

            sb.append(" and " + this.tensPlaceParser.parse(centumReminder));

         } else if (centumReminder % 10 > 0) {

            sb.append(" and " + this.unitParser.parse(centumReminder));
         }

      }

      return sb.toString();
   }

   public void setTensPlaceParser(Parser tensPlaceParser) {
      this.tensPlaceParser = tensPlaceParser;
   }

   public void setUnitParser(Parser unitParser) {
      this.unitParser = unitParser;
   }
}
